<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="6" :md="12" :sm="24">
            <a-form-item label="类型">
              <a-select default-value="1" placeholder="全部类型" v-model="queryParam.type" >
                <a-select-option :value="item.val" v-for="(item, index) in typeUl" :key="index" >{{ item.name }}</a-select-option >
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="12" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons" >
              <a-button type="primary" @click="searchQuery" icon="search" >查询</a-button >
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px" >重置</a-button >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="crudCreate" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table 
        ref="table" 
        size="middle" 
        bordered
        rowKey="id" 
        :scroll="{ x: 1300 }"
        :columns="columns" 
        :dataSource="tableData" 
        :loading="loading" 
        @change="handleTableChange"
      >
        <!--操作-->
        <span slot="action" slot-scope="text, record" >
          <a-popconfirm title="确定删除吗?" @confirm="() => crudDelete(record.id)" okText="删除" cancelText="取消">
            <a-button type="danger" icon="delete" />
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <tag-list-modal ref="updateForm" @closeModal="closeModal"></tag-list-modal>
  </a-card>
</template>

<script>
import TagListModal from './modules/TagListModal'
import ApiTree from "@/api/common/tagList";
import { Slime, crud } from "@/mixins/slime";

export default {
  name: "tagList",
  mixins: [Slime],
  components: {
    TagListModal
  },
  data() {
    return {
      tableData: [],
      columns: [
        {
          title: "名称",
          align: "center",
          dataIndex: "name",
        },
        {
          title: "类型",
          align: "center",
          dataIndex: "type",
          customRender: function(type) {
            if(type == 1){
              return '商家标签'
            }else if(type == 2){
              return '用户标签'
            }else{
              return '其他'
            }
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      typeUl:[
        {name:'商家标签', val:1},
        {name:'用户标签', val:2},
      ],
    };
  },
  created() {
    this.queryParam.type = 1
    crud(ApiTree);
    this.loadData();
  },
  methods: {
    // 加载表格数据
    loadData(arg) {
      this.loadDataPack(arg).then((res) => {
        let tableData = [];
        if (res.result) {
          tableData = res.result;
        }
        this.tableData = tableData;
      });
    },
    closeModal(){
      this.loadData();
    },
    searchReset() {
      this.queryParam = {};
      this.queryParam.type = 1
      this.$router.push({ query: {} })
      this.loadData(1);
    },
  },
};
</script>
<style scoped>
.tag_type{
  margin: 20px 0px;
}
</style>